<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/6/20
 * Time: 17:17
 */

namespace zhtfrontend\controllers;

use common\components\helpers\Fun;
use yii\db\Query;
use zhtfrontend\components\bases\BaseController;
use yii\data\Pagination;
use zhtfrontend\models\datas\CheckCount;

class ClassfireController extends BaseController
{
    //班主任列表
    public function actionIndex()
    {
        $search_data = \Yii::$app->request->get();
        $model = (new Query())
            ->select(['COUNT(cc.id) as count', 'm.name'])
            ->from('{{%check_count}} cc')
            ->leftJoin('{{%mechanic}} m', 'cc.mechanic_id = m.id');
            if (!empty($search_data['date'])) {

            } else {
                $start = strtotime(date('Y-m-21', strtotime('-1 month')));
                $start = strtotime(date('2017-10-21'));
                $end = strtotime(date('2017-11-20 23:59:59'));
                $model->where(['between', 'cc.class_time', $start, $end]);
            }
            if (!empty($search_data['name'])) {
                $model->andWhere(['like', 'name', $search_data['name']]);
            }
            if (!empty($search_data['status'])) {
                $model->andWhere(['status' => $search_data['status']]);
            }
//            $data = $model->createCommand(Fun::getSiteDb())->getRawSql();


            $pages = new Pagination(['totalCount' => $model->count('*',Fun::getSiteDb()), 'pageSize' => 14, 'params' =>$_GET]);
            $data = $model->offset($pages->offset)->limit($pages->limit)->all(Fun::getSiteDb());
            print_r($data);
            die;
            return $this->render('index', ['model' => $data, 'form' => $_GET, 'pages' => $pages]);
    }


}